package com.ntschy.web.controller.bt;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ntschy.bt.entity.dataobject.BtHelp.BtHelp;
import com.ntschy.bt.entity.dataobject.BtHelp.SysDept;
import com.ntschy.bt.entity.dto.BtHelpDTO.ReplyDTO.BtHelpReplyDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.ReplyDTO.BtHelpReplyPageDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.ReviewDTO.BtHelpAuditDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.ReviewDTO.BtHelpReviewPageDTO;
import com.ntschy.bt.entity.enums.BtHelpStatusEnum;
import com.ntschy.bt.entity.mapstruct.BtHelpMapstruct;
import com.ntschy.bt.entity.mapstruct.BtHelpReplyMapstruct;
import com.ntschy.bt.entity.mapstruct.BtHelpReviewMapstruct;
import com.ntschy.bt.entity.vo.BtHelp.Assign.BtHelpAssignDetailsVO;
import com.ntschy.bt.entity.vo.BtHelp.Reply.BtHelpReplyDetialsVO;
import com.ntschy.bt.entity.vo.BtHelp.Reply.BtHelpReplyPageVO;
import com.ntschy.bt.entity.vo.BtHelp.Review.BtHelpReviewPageVO;
import com.ntschy.bt.service.IBtHelp.IBtHelpReplyService;
import com.ntschy.bt.service.IBtHelp.impl.BtHelpReplyServiceImpl;
import com.ntschy.common.core.AjaxPageResult;
import com.ntschy.common.core.AjaxResult;
import com.ntschy.common.core.controller.BaseController;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author
 * @since
 */
@Validated
@RestController
@RequestMapping("/bt/help")
public class BtHelpReplyController extends BaseController {

    @Resource
    private IBtHelpReplyService btHelpReplyService;

    // * ================================================基础增删改查BEGIN============================================= *
    /**
     * 一键求助求助反馈分页列表
     *
     * @param btHelpReplyPageDTO
     * @return
     */
    @ApiOperation(value = "查询求助反馈列表", notes = "")
    @ApiImplicitParam(name = "pageSupplyShop", value = "求助反馈分页查询", required = true, dataType = "BtHelpReviewPageDTO")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/pageWaitReplyHelp")
    public AjaxPageResult<BtHelpReviewPageVO> pageWaitReplyHelp(@RequestBody BtHelpReplyPageDTO btHelpReplyPageDTO) {
        Page<BtHelp> page = PageHelper.startPage(btHelpReplyPageDTO.getCurrPage(), btHelpReplyPageDTO.getPageSize());
        BtHelp bthelp = BtHelpReplyMapstruct.BT_HELP_Reply_MAP_STRUCT.pagetableDto(btHelpReplyPageDTO);
        List<BtHelp> btHelps = btHelpReplyService.pageHelpReply(bthelp);
        List<BtHelpReplyPageVO> btHelpReplyPageVO = BtHelpReplyMapstruct.BT_HELP_Reply_MAP_STRUCT.pagePustrespone(btHelps);
        return buildPageResult(btHelpReplyPageVO,page);

    }



    /**
     * 求助回复详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "求助回复详情", notes = "")
    @ApiImplicitParam(name = "fetchWaitReplyHelp", value = "求助回复详情", required = true, dataType = "String")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @GetMapping("/fetchWaitReplyHelp")
    public AjaxResult<BtHelpReplyDetialsVO> fetchWaitReplyHelp(@NotBlank(message = "ID不能为空") String id){
        BtHelp btHelp = btHelpReplyService.detailsHelpReply(id);
        BtHelpReplyDetialsVO btHelpReplyDetialsVO = BtHelpReplyMapstruct.BT_HELP_Reply_MAP_STRUCT.bthelpCHANGEreplydetialsvo(btHelp);
        return AjaxResult.success("成功",btHelpReplyDetialsVO);

    }


    /**
     *求助回复
     *
     * @param btHelpReplyDTO
     * @return
     */
    @ApiOperation(value = "求助回复", notes = "")
    @ApiImplicitParam(name = "updateReplyHelp", value = "求助回复", required = true, dataType = "btHelpReplyDTO")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/updateReplyHelp")
    public AjaxResult<String> updateReplyHelp(@RequestBody BtHelpReplyDTO btHelpReplyDTO){
        BtHelp btHelp = BtHelpReplyMapstruct.BT_HELP_Reply_MAP_STRUCT.bthelpreplydtoCHANGEbthelp(btHelpReplyDTO);
        BtHelp verify = btHelpReplyService.detailsHelpReply(btHelp.getId());
        int result = 0;
        if(verify.getStatus() == BtHelpStatusEnum.TO_REPLY){
                btHelp.setStatus(BtHelpStatusEnum.TO_BE_ENTERED);
                result = btHelpReplyService.updateReply(btHelp);
        }
        return toAjax(result,"审核成功","审核失败");

    }

    // * ================================================基础增删改查BEGIN============================================= *

}
